﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Lego.Ev3.Core;
using System.Diagnostics;

namespace Enough.Lego.Mindstorms.WP.Model
{
    class TurtleSnapp3rController : BaseController
    {
        public async Task MoveAsync(int leftPower, int rightPower)
        {
            await EnsureIsConnectedAsync();
            await Brick.DirectCommand.TurnMotorAtPowerAsync(OutputPort.B, leftPower);
            await Brick.DirectCommand.TurnMotorAtPowerAsync(OutputPort.C, rightPower);
        }

        public async Task MoveRightAsync(int rightPower)
        {
            await EnsureIsConnectedAsync();
            await Brick.DirectCommand.TurnMotorAtPowerAsync(OutputPort.B, rightPower);
        }

        public async Task MoveLeftAsync(int leftPower)
        {
            await EnsureIsConnectedAsync();
            await Brick.DirectCommand.TurnMotorAtPowerAsync(OutputPort.C, leftPower);
        }

        public async Task StopMovementAsync()
        {
            await EnsureIsConnectedAsync();
            await Brick.DirectCommand.StopMotorAsync(OutputPort.B, true);
            await Brick.DirectCommand.StopMotorAsync(OutputPort.C, true);
        }

        public async Task OpenAsync()
        {
            await EnsureIsConnectedAsync();
            await Brick.DirectCommand.TurnMotorAtPowerAsync(OutputPort.A, -10);
        }

        public async Task CloseAsync()
        {
            await EnsureIsConnectedAsync();
            await Brick.DirectCommand.TurnMotorAtPowerAsync(OutputPort.A, 10);
        }

        public async Task TurnAsync(int power)
        {
            await EnsureIsConnectedAsync();
            await Brick.DirectCommand.TurnMotorAtPowerAsync(OutputPort.A, power);
        }

        public async Task StopOpenCloseAsync()
        {
            await EnsureIsConnectedAsync();
            await Brick.DirectCommand.StopMotorAsync(OutputPort.A, true);
        }
    }
}
